<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateOrderFieldsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('order_fields')) {
            Schema::create('order_fields', function (Blueprint $table) {
                $table->id();
                $table->string('name', 64)->comment('字段标识名,英文,唯一');
                $table->string('label', 64)->comment('字段中文名');
                $table->string('placeholder')->nullable()->comment('字段提示');
                $table->string('helper')->nullable()->comment('字段协助说明');
                $table->string('type', 32)->default('input')->comment('控件类型');
                $table->string('default_content')->nullable()->comment('默认数据');
                $table->string('options')->nullable()->comment('在某些控件上作为选择数据');
                $table->string('rule_data')->default('')->comment('输入规则');
                $table->string('rule_data_err')->default('')->comment('对应规则错误提示');
                $table->enum('required', ['y', 'n'])->default('n')->comment('是否必填');
                $table->string('required_err_msg')->nullable()->commen('未填错误提示');
                $table->integer('order')->default(0)->comment('排序, ASC 方式');
                $table->json('meta')->nullable()->comment('数据元，一般作为对应控件的参数');
                $table->string('more')->nullable()->comment('扩展字段');
                $table->softDeletes();
                $table->timestamps();
            });
            DB::statement("ALTER TABLE `order_fields` comment '订单字段扩展表'");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order_fields');
    }
}
